(function ($) {
	var code = $("#ucode").val();
	var id = $("#id").val();
    var selfMedia = {
        init : function(){
          
            var that = this;
            var u = navigator.userAgent;
            var ua = navigator.userAgent.toLowerCase();
            var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; 
            var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); 
           if(isiOS){
                $(".go").on('click', function (event) {
                    //跳转到ios下载地址 
                    window.location.href='https://itunes.apple.com/us/app/%E8%B1%A1%E6%BC%BE/id1296514019?l=zh&ls=1&mt=8'

                });
            }else if(isAndroid){

                $(".go").bind('touchstart', function (event) {
                    window.location.href='http://shouji.baidu.com/software/22737102.html'
                });
            }
           //  var height= window.screen.height;
           //  console.log(height)
           // var iheight=height-98;
           // $('.inp').css('top',iheight+'px');
           
           $.ajax({
		         url: "/platform/mission/gernerateNickName",
		         type: "get",
		         data:{"ip":$("#ip").val()},
		         success: function(res) {
		              var  data=res.data;
		              localStorage.setItem('name',data);              
		              localStorage.setItem('imgUrl',"/upload/avatar/x.jpg");   
		        }
		});
            
           	that.getInfor();
			//that.getPicList();
			that.getComment();
			that.getTaskWhInfo();
			that.bindEvent();

        },
    bindEvent:function(){
    	
//    	$('input[type="text"]').on('click', function () {
//            var target = this;
//            setTimeout(function(){
//            	var pannel = document.getElementById("cInput");
//            	pannel.scrollIntoView(false);
////            	pannel.scrollIntoView();
////            	pannel.scrollIntoView(true);
////            	pannel.scrollIntoViewIfNeeded();
//            },400);
//        });
        $('.plBtn').on('click',function(){
            $('.oInput').val('')
            $('.oInput').attr('placeholder','我也来说一句');
            $('.oInput').focus();
            $('.oInput').attr('flag','nohave');
            $("#toUserNickName").val("");
            $("#toUserUrl").val("");
            $("#commentBtn").trigger("click");
            
        })
        $(".plMainCon").on("click",".commBox",function(){
        	
        	//$('.oInput').focus();
            var index=$(this).index();
            var toName=$('.commBox').eq(index-1).find('.userName').html();
            var toUrl=$('.commBox').eq(index-1).find('.userUrl').attr("src");
//            $('.oInput').attr('flag','have');
//            $('.oInput').attr('toName',toName);
//            $('.oInput').attr('placeholder','回复'+toName);
            $("#toUserNickName").val(toName);
            $("#toUserUrl").val(toUrl);

            layer.open({
				   type: 2,
				   skin: 'layui-layer-rim', //加上边框
				   area: ['90%'], //宽高
				   content:["/platform/mission/commentModal",'no'],
				   closeBtn:0,
				   title:"请输入你的评论内容信息",
				   success: function(layero, index){
					   var body = layer.getChildFrame('body', index);
					   var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
					   layer.iframeAuto(index)
					   var parent = window.parent.document;
					   var toUserNickName = $("#toUserNickName",parent).val();
					   if(toUserNickName!=""){
						   body.find('input').focus();
						   body.find('input').attr("placeholder","回复"+toUserNickName);
						   body.find('input').attr('flag','have');
				           body.find('input').attr('toName',toUserNickName);
					   }
				   }
				 });
            
        })
    },
    getInfor:function(){
         $.ajax({
		         url: "/platform/mission/getFairInfo",
		         type: "get",
		         data:{"ucode":code},
		         success: function(res) {
		              var  data=res.data;
		//                var data={
		//                    'nickName':'Cloud_Hao',
		//                    'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
		//                    'recommend':'看过来，这里最精彩，跟我一起做像样的网红！'
		//                }
		                $('.name').html(data.nickName)
		                $('.imgUrl').attr('src',data.avatarUrl)
		                
		        }
		    });
       //获取微信登录用户信息 
	    var ua = navigator.userAgent.toLowerCase();
		var isWeixin = ua.indexOf('micromessenger') != -1;
		if(isWeixin&&($("#code").val().length>0)){
			$.ajax({
			         url: "/platform/mission/getUserInfoFromWeixin",
			         type: "get",
			         data:{"code":$("#code").val()},
			         success: function(res) {
			              var  data=res.data;
			              localStorage.setItem('name', data.nickName);              
			              localStorage.setItem('imgUrl', data.avatarUrl);    
			        }
			});
		}
	},
    getPicList:function(){
         $.ajax({
         url: "/platform/mission/getTaskPicList",
         type: "get",
          data:{"id":id},
         success: function(res) {
              var  data=res.data;
//                var data={
//                    'picList':[
//                        'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
//                        'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
//                        'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
//                    ]
//                }
                var picList=data.picList;
                 var picHtml;

                for(var i=0;i<picList.length;i++){
                    if((i+1)%2==1){
                        picHtml="<div class='wayOne'><img src='"+picList[i]+"' class='imgOne'></div>"
                    }else{
                        picHtml="<div class='wayTwo'><img src='"+picList[i]+"' class='imgTwo'></div>"
                    }
                    $('.advertise').append(picHtml)
                }
        }
    });
    },
    getTaskWhInfo:function(){
    	  $.ajax({
    	         url: "/platform/mission/getTaskWhInfo",
    	         type: "get",
    	         data:{"ucode":code},
    	         success: function(res) {
    	        	 $(".view_num").html(res.data.click_num+"次");
    	        	 $('.reasons').html(res.data.reason)
    	         }
    	  })
    },
    getComment:function(){
               $.ajax({
         url: "/platform/mission/getComment",
         type: "get",
         data:{"taskId":id,"ucode":code},
         success: function(res) {
              var  data=res.data;
//                var data={
//                    'commentList':[
//                        {
//                            'id':1,
//                            'comments':'哼哼评论你个大傻子，哼哼哈嘿',
//                            'fromUser':{
//                                'userId':1,
//                                'nickName':'章泽西',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':null
//                        },{
//                            'id':2,
//                            'comments':'今天天气好晴朗！',
//                            'fromUser':{
//                                'userId':2,
//                                'nickName':'啊哈西',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':{
//                                'userId':3,
//                                'nickName':'云云',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                        },{
//                            'id':3,
//                            'comments':'我喜欢这篇文章，讲的好好的样子~你觉得呢',
//                            'fromUser':{
//                                'userId':4,
//                                'nickName':'丹丹',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':{
//                                'userId':1,
//                                'nickName':'章泽西',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                        },{
//                            'id':4,
//                            'comments':'你评论你个大傻子，哼哼哈嘿说的是个啥啊',
//                            'fromUser':{
//                                'userId':1,
//                                'nickName':'你说呢',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':null
//                        },{
//                            'id':1,
//                            'comments':'我的妈呀，我喜欢你哈哈哈评论你个大傻子，哼哼哈嘿',
//                            'fromUser':{
//                                'userId':1,
//                                'nickName':'叫什么',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':{
//                                'userId':5,
//                                'nickName':'宝宝蛋',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                        },{
//                            'id':5,
//                            'comments':'别理我评论你个大傻子，哼哼哈嘿',
//                            'fromUser':{
//                                'userId':1,
//                                'nickName':'不知道诶',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':null
//                        },{
//                            'id':6,
//                            'comments':'哼哼评论你个大傻子，哼哼哈嘿',
//                            'fromUser':{
//                                'userId':1,
//                                'nickName':'好的吧',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':{
//                                'userId':1,
//                                'nickName':'多大的',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                        },{
//                            'id':7,
//                            'comments':'哼哼评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿评论你个大傻子，哼哼哈嘿',
//                            'fromUser':{
//                                'userId':1,
//                                'nickName':'章泽西',
//                                'avatarUrl':'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLQdE70QPqK4F1iaPsAv9sJP2hz3bJe9kD5GbztSHnFcIJMUFziaTIe0V482YgkJy2oibQulnibjA8LFQ/0',
//                            },
//                            'toUser':null
//                        }
//                    ]
//                }
                var commentList=data.commentList;
                $('.zpl').html(commentList.length)
                for(var i=0;i<commentList.length;i++){
                    var commBoxHtml="<div class='commBox'>";
                    commBoxHtml+="<div class='namePic'><img src='"+commentList[i].fromUser.avatarUrl+"' class='userUrl'><em class='userName'>"+commentList[i].fromUser.nickName+"</em></div>"
                    if(commentList[i].toUser==null){
                          commBoxHtml+='<div class="toBox"><div class="comcon">'+commentList[i].comments+'</div></div><div class="bai"></div>'  
                    }else{
                        commBoxHtml+='<div class="toBox"><div class="comcon">回复<em class="toName">'+commentList[i].toUser.nickName+'</em>:<em style="margin-left:.2rem">'+commentList[i].comments+'</em></div></div><div class="bai"></div>'
                    }
                    commBoxHtml+="</div>";
                    $('.plMainCon').append(commBoxHtml)
                }
        }
    });

    }
    
    }.init();
})(jQuery)